/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-08-22
 * Time: 19:45
 */
//https://leetcode.cn/problems/subarray-sum-equals-k/
public class Test {
    public static int subarraySum(int[] nums, int k) {
        int size=nums.length;
        long[] arr=new long[size+1];
        long sum=0;
        for(int i=0;i<size;i++){
            sum+=nums[i];
            arr[i+1]=sum;
        }
        int n=0;
        for(int i=0;i<size;i++){
            for(int j=i+1;j<size+1;j++){
                if(arr[j]-arr[i]==k)
                    n++;
            }
        }
        return n;
    }

    public static void main(String[] args) {
        int[] arr={1,2,3,4,5,6,7,8,9,0};
        System.out.println(subarraySum(arr,5));
    }
}
